package actions;

import java.sql.SQLException;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.StudentForm;
import model.CountriesModel;
import model.UserModel;

public class StudentAddressAction extends Action {

	private static final boolean DEBUG = true;
	//private static final int UNKNOWN = -1;
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws DbException {
	
		// get student address from form
		StudentForm sform = (StudentForm)form;
		
		String address = sform.getAddress();
		String city = sform.getCity();
		String state = (sform.getState() == null)? "" : sform.getState();
		String zip_code = sform.getZip_code();
		String country_code = (sform.getCountry_code() == null)? "" : sform.getCountry_code();
		String area_code = sform.getArea_code();
		String telephone = sform.getTelephone();
		
		if (DEBUG) {
			System.err.println("StudentAddressAction: saving address(" + address +")");
			System.err.println("StudentAddressAction: saving city(" + city +")");
			System.err.println("StudentAddressAction: saving state(" + state +")");
			System.err.println("StudentAddressAction: saving zip_code(" + zip_code +")");
			System.err.println("StudentAddressAction: saving country_code(" + country_code +")");
			System.err.println("StudentAddressAction: saving area_code(" + area_code +")");
			System.err.println("StudentAddressAction: saving telephone(" + telephone +")");
		}
		
		// save student address and telephone into session
		request.getSession().setAttribute("address", address);
		request.getSession().setAttribute("city", city);
		request.getSession().setAttribute("state", state);
		request.getSession().setAttribute("zip_code", zip_code);
		request.getSession().setAttribute("country_code", country_code);
		request.getSession().setAttribute("area_code", area_code);
		request.getSession().setAttribute("telephone", telephone);
		
		// store StudentForm into session
		sform = (StudentForm)request.getSession().getAttribute("sform");
		
		sform.setAddress(address);
		sform.setCity(city);
		sform.setState(state);
		sform.setZip_code(zip_code);
		sform.setCountry_code(country_code);
		sform.setArea_code(area_code);
		sform.setTelephone(telephone);
		
		request.getSession().setAttribute("sform", sform);
		
		
		if (request.getSession().getAttribute("residence").equals("United States")) {
			return mapping.findForward("skip");
		}
		else {
			return mapping.findForward("continue");
		}
	}
	
}
